package com.grj.park.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.grj.park.common.R;
import com.grj.park.domain.ChargingPiles;
import com.grj.park.domain.ChargingStations;
import com.grj.park.service.ChargingPilesService;
import com.grj.park.service.ChargingStationsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("chargingPiles")
public class ChargingPilesController {

    private final ChargingPilesService chargingPilesService;

    @GetMapping
    public R<List<ChargingPiles>> getChargingPiles(){
        return R.ok(chargingPilesService.list());
    }

    @PostMapping
    public R<?> saveChargingPilesService(@RequestBody ChargingPiles chargingPiles){
        LambdaQueryWrapper<ChargingPiles> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ChargingPiles::getChargerName, chargingPiles.getChargerName());
        ChargingPiles one = chargingPilesService.getOne(queryWrapper);
        if (one != null){
            return R.fail("充电枪名字已存在");
        }
        chargingPilesService.save(chargingPiles);
        return R.okMsg("添加充电枪成功");
    }
}
